package com.yanqu.road.logic.pb;

import com.yanqu.road.entity.rank.yrank.UserYRank;
import com.yanqu.road.pb.rank.YRankProto;

import java.math.BigInteger;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

public class YRankPb {

    public static YRankProto.UserYRankMsg.Builder parseUserYRankMsg(UserYRank userYRank) {
        YRankProto.UserYRankMsg.Builder builder = YRankProto.UserYRankMsg.newBuilder();
        builder.setUserId(userYRank.getUserId());
        builder.setBaseInfo(PlayerBasePb.parsePlayerBaseTempMsg(userYRank.getUserBaseInfo()));
        builder.setValue(userYRank.getValue().toString());
        builder.setParam(userYRank.getParam());
        builder.setUpdateTime(userYRank.getUpdateTime());
        return builder;
    }

    public static UserYRank parseUserYRank(int activityId, int groupId, String idKey, YRankProto.UserYRankMsg msg) {
        UserYRank userYRank = new UserYRank();
        userYRank.setGroupId(groupId);
        userYRank.setActivityId(activityId);
        userYRank.setIdKey(idKey);
        userYRank.setUserId(msg.getUserId());
        userYRank.setUserBaseInfo(PlayerBasePb.parseBaseUserInfo(msg.getBaseInfo()));
        userYRank.setValue(new BigInteger(msg.getValue()));
        userYRank.setParam(msg.getParam());
        userYRank.setUpdateTime(msg.getUpdateTime());
        return userYRank;
    }

    public static ConcurrentHashMap<Long, Integer> parsePosMap(List<YRankProto.UnionYRankPosMsg> msgList) {
        ConcurrentHashMap<Long, Integer> posMap = new ConcurrentHashMap<>();
        for (YRankProto.UnionYRankPosMsg msg : msgList) {
            posMap.put(msg.getUserId(), msg.getPos());
        }
        return posMap;
    }

}
